package com.bytedance.ttnet.a;

import android.content.SharedPreferences;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

final class d extends Thread {
    private final AppConfig b;
    private final boolean a;

    d(AppConfig arg1, String arg2, boolean arg3) {
        super(arg2);
        this.b = arg1;
        this.a = arg3;
    }

    public final void run() {
        int v3_1;
        JSONArray v11;
        int v0 = 102;
        int v2 = 2;
        AppConfig v9 = this.b;
        boolean v3 = this.a;
        v9.k();
        if (!v3) {
            v9.mWeakHandler.sendEmptyMessage(v0);
            return;
        }

        JSONObject v10 = new JSONObject();
        int v8 = 0;
        int v4 = 0;
        boolean v5 = false;
        while (v8 < v2) {
            boolean v6 = v8 == 0 ? true : false;
            try {
                v11 = new JSONArray();
                if (v9.a(v11, v6)) {
                    v3_1 = 101;
                    if (v6) {
                        v5 = true;
                    }

                    if (v6 || !v5) {
                        try {
                            synchronized (v9) {
                                SharedPreferences.Editor v0_3 = v9.mContext.getSharedPreferences("ss_app_config", 0).edit();
                                v0_3.putBoolean("https_available", v5);
                                v0_3.commit();
                            }
                        } catch (Throwable v0_2) {
                            v0_2.printStackTrace();
                        }
                    }
                    AppConfig.b = v5;
                    if (v6) {
                        v0 = 1;
                    } else {
                        v0 = v2;
                    }
                    v4 |= v0;
                } else {
                    v3_1 = v0;
                }

                String v0_4 = v6 ? "https" : "http";
                v10.put(v0_4, v11);
                ++v8;
                v0 = v3_1;
                continue;
            } catch (JSONException v1) {
                v1.printStackTrace();
            }
        }

        try {
            v10.put("available_state", v4);
        } catch (JSONException v1) {
            v1.printStackTrace();
        }
        com.bytedance.ttnet.cc.a().a(v9.mContext, v10);
        v9.mWeakHandler.sendEmptyMessage(v0);
    }
}

